﻿using System;
using WebUI.Lang;

namespace WebUI
{
    public partial class Adler : System.Web.UI.MasterPage
    {
        public string languagecheck = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        public string GetText(string name)
        {
            return AdlerBasePage.GetText(name);
        }

        private void BindData()
        {
            string email = "";
            string name = "";
            if (Request.Cookies["adler_email"] != null && Request.Cookies["adler_name"] != null)
            {
                email = Request.Cookies["adler_email"].Value;
                name = Request.Cookies["adler_name"].Value;

                if (email != null && email != "" && name != null && name != "")
                {
                    lblLogin.Visible = false;
                    lblMemInfo.Visible = true;
                    linkLogOut.Visible = true;
                    lblMemInfo.Text = "Welcome " + name;
                }
            }
            if (Request.Cookies["langId"] != null)
            {
                languagecheck = Request.Cookies["langId"].Value;
                if (languagecheck == "1")
                {
                    divenglish.Visible = true;
                    divvietnam.Visible = false;
                }
                else
                {
                    divenglish.Visible = false;
                    divvietnam.Visible = true;
                }
            }
            else
                languagecheck = "2";
        }

        protected void linkLogOut_Click(object sender, EventArgs e)
        {
            Response.Cookies.Get("adler_email").Value = null;
            Response.Cookies.Get("adler_name").Value = null;
            Response.Redirect("/Default.aspx");
        }

        //protected void drpLangId_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    if (drpLangId.SelectedIndex != -1)
        //    {
        //        Response.Cookies["langId"].Value = drpLangId.SelectedValue;
        //        Response.Redirect(Request.UrlReferrer.AbsoluteUri);
        //    }
        //}

        protected void imgbtnEnglish_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            Response.Cookies["langId"].Value = "2";
            Response.Redirect(Request.UrlReferrer.AbsoluteUri);
        }

        protected void imgbtnVietNam_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            Response.Cookies["langId"].Value = "1";
            Response.Redirect(Request.UrlReferrer.AbsoluteUri);
        }
    }
}